package com.hzjob.dao.one2one;

import org.hibernate.Session;

import com.hzjob.domain.one2one.Tperson;
import com.hzjob.util.MySessionFactory;

public class PersonDAOImpl implements PersonDao {

	@Override
	public Tperson findPersonById(Integer id) {
		Session session = MySessionFactory.currentSession(2);
		session.beginTransaction();
		Tperson person = (Tperson) session.get(Tperson.class, id);
		session.getTransaction().commit();
		MySessionFactory.closeSession();
		return person;
	}

	@Override
	public Tperson addPerson(Tperson person) {
		Session session = MySessionFactory.currentSession(2);
		session.beginTransaction();
		session.save(person);
		session.getTransaction().commit();
		MySessionFactory.closeSession();
		return person;
	}

	@Override
	public void removePerson(Tperson person) {
		Session session = MySessionFactory.currentSession(2);
		session.beginTransaction();
		session.delete(person);
		session.getTransaction().commit();
		MySessionFactory.closeSession();
	}

}
